-- @testpoint: 创建约束触发器设置启动推迟

--创建表
CREATE TABLE test_trigger_src_tbl0(id1 INT, id2 INT, id3 INT) WITH (ORIENTATION = ROW);
CREATE TABLE test_trigger_des_tbl0(id1 INT, id2 INT, id3 INT);
--创建触发器函数
CREATE OR REPLACE FUNCTION tri_insert_func01() RETURNS TRIGGER AS
$$
DECLARE
BEGIN
	INSERT INTO test_trigger_des_tbl0 VALUES(NEW.id1, NEW.id2, NEW.id3);
	RETURN NEW;
END
$$ LANGUAGE PLPGSQL;
/
--创建触发器
CREATE CONSTRAINT TRIGGER insert_trigger01 AFTER INSERT ON test_trigger_src_tbl0  DEFERRABLE FOR EACH ROW EXECUTE PROCEDURE tri_insert_func01();
--执行INSERT触发事件并检查触发结果
INSERT INTO test_trigger_src_tbl0 VALUES(100,200,300);
SELECT * FROM test_trigger_src_tbl0;
SELECT * FROM test_trigger_des_tbl0;
--清理资源
DROP FUNCTION tri_insert_func01() cascade;
DROP TABLE test_trigger_src_tbl0;
DROP TABLE test_trigger_des_tbl0;